package com.plug.common.spring.intercept;

import com.plug.common.Const;
import com.plug.common.spring.utils.PropertyConfigurer;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * RequestConfigInterceptor
 *
 * @author Archx[archx@foxmail.com]
 * @date 2016/6/30 0030
 */
public class RequestConfigInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        if (modelAndView != null) {
            // 配置信息

            // 插件静态资源访问地址
            modelAndView.addObject(Const.SESSION_PLUGIN_STATIC_RESOURCE, PropertyConfigurer.getValue(
                    Const.PLUGIN_STATIC_RESOURCE));
            // 公共静态资源访问地址
            modelAndView.addObject(Const.SESSION_PUBLIC_STATIC_RESOURCE, PropertyConfigurer.getValue(
                    Const.PUBLIC_STATIC_RESOURCE));
            // 退出登录地址
            modelAndView.addObject(Const.SESSION_LOGOUT_URL, PropertyConfigurer.getValue(Const.SSO_LOGIN_OUT_URL));
        }
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {

    }
}
